package uvt.gui.mainframe.object.observer;

import java.util.ArrayList;

public class ConcreteObservable implements Observable {
	
	private ArrayList<Observer> listObservers;
	
	private static ConcreteObservable vehiclePanelObservableInstance;
	private static ConcreteObservable routePanelObservableInstance;
	private static ConcreteObservable stationNameObservableInstance;
	private static ConcreteObservable streetNameObservableInstance;
	
	public static ConcreteObservable getVehiclePanelObservableInstance() {
		if(vehiclePanelObservableInstance == null) {
			vehiclePanelObservableInstance = new ConcreteObservable();
		}
		return vehiclePanelObservableInstance;
	}
	
	public static ConcreteObservable getRoutePanelObservableInstance() {
		if(routePanelObservableInstance == null) {
			routePanelObservableInstance = new ConcreteObservable();
		}
		return routePanelObservableInstance;
	}
	
	public static ConcreteObservable getStationNameObservableInstance() {
		if(stationNameObservableInstance == null) {
			stationNameObservableInstance = new ConcreteObservable();
		}
		return stationNameObservableInstance;
	}
	
	public static ConcreteObservable getStreetNameObservableInstance() {
		if(streetNameObservableInstance == null) {
			streetNameObservableInstance = new ConcreteObservable();
		}
		return streetNameObservableInstance;
	}
	
	private ConcreteObservable() {
		listObservers = new ArrayList<Observer>();
	}
	
	public void stateChanged() {	
		notifyObject();
	}
	
	public void attach(Observer observer) {
		listObservers.add(observer);
	}
	
	public void detach(Observer observer) {
		listObservers.remove(observer);
	}
	
	public void notifyObject() {
		for(Observer obs : listObservers) {
			obs.update();
		}
	}
}
